package asset

import (
	"base"
	. "game_server/logic/internal"
	"game_server/model"
	"proto/asset"
	"proto/base"
)

type assetService struct {
}

func init() {
	Service.Register(new(assetService))
}

func (*assetService) Name() string {
	return "proto_asset"
}

func (*assetService) TestAdd(player *model.Player, request *proto_asset.TestAdd) (err error) {
	addItems := []*base.AssetItem{
		{
			Id:    request.Id,
			Count: request.Count,
		},
	}

	_, err = system.Handle(
		player,
		addItems,
		nil,
		proto_base.ChangeReason_Test,
		nil,
	)

	rpc.OnTestAdd(player, err)

	return
}

func (*assetService) TestRemove(player *model.Player, response *proto_asset.TestRemove) (err error) {
	var entity interface{}
	if response.Entity != "" {
		entity = response.Entity
	}

	removeItems := []*base.AssetItem{
		{
			Id:     response.Id,
			Count:  response.Count,
			Entity: entity,
		},
	}

	_, err = system.Handle(
		player,
		nil,
		removeItems,
		proto_base.ChangeReason_Test,
		nil,
	)

	rpc.OnTestRemove(player, err)

	return
}
